<?php

require_once PHP_UI_PATH . DS . 'Constraint.php';

class ConstraintFactory {

    private static $instance;
    private $Constraints = array();

    public function getConstraints() {
        return $this->Constraints;
    }

    /**
     *
     * @param string $type
     * @return Constraint
     */
    public function getConstraint($type) {
        $return = null;

        if (!array_key_exists($type, $this->Constraints)) {
            if (class_exists($type) && array_search("Constraint", class_implements($type))) {
                $Constraint = new $type();
                $this->Constraints[$type] = $Constraint;
                $return = $Constraint;
            }
        } else {
            $return = $this->Constraints[$type];
        }

        return $return;
    }

    private function __construct() {
        
    }

    /**
     *
     * @return ConstraintFactory
     */
    public static function instance() {
        if (self::$instance == null) {
            self::$instance = new ConstraintFactory();
        }
        return self::$instance;
    }

}

?>
